package com.ltu.listenre;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

import com.ltu.EntryApplication;


/**  
 * @Description: 
 * @author: 若尘  
 * @date 2019年7月7日 上午11:43:22
 * @version V1.0  
 */
//@Configuration
//@Import(value=EntryApplication.class)
public class RedisPubsubKeyConfig {
	@Autowired
	private RedisMessageListen redisMessageListen;
//	@Value("${spring.redis.database}")
    private Integer db=0;
	@Bean
	public ChannelTopic  expiredTopic(){
		return new ChannelTopic("__keyevent@"+db.intValue()+"__:expired");
	}
	@Bean
	public  RedisMessageListenerContainer redisMessageListenerContainer(@Autowired RedisConnectionFactory redisConnectionFactory){
		RedisMessageListenerContainer redisMessageListenerContainer = new RedisMessageListenerContainer();
		redisMessageListenerContainer.setConnectionFactory(redisConnectionFactory);
		redisMessageListenerContainer.addMessageListener(redisMessageListen, expiredTopic());
		return redisMessageListenerContainer;
	}
	
	
}
